# Maintainer: Peter Budai <peterbudai@hotmail.com>

_realname=nbconvert
pkgbase=mingw-w64-python-jupyter-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-jupyter-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-jupyter-${_realname}")
pkgver=7.2.5
pkgrel=1
pkgdesc="Convert Jupyter notebooks to other formats (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/jupyter/nbconvert'
license=('spdx:BSD')
options=(!strip)
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-bleach
    ${MINGW_PACKAGE_PREFIX}-python-beautifulsoup4
    ${MINGW_PACKAGE_PREFIX}-python-defusedxml
    ${MINGW_PACKAGE_PREFIX}-python-jinja
    ${MINGW_PACKAGE_PREFIX}-python-jupyter_core
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbclient
    ${MINGW_PACKAGE_PREFIX}-python-jupyter-nbformat
    ${MINGW_PACKAGE_PREFIX}-python-jupyterlab-pygments
    ${MINGW_PACKAGE_PREFIX}-python-lxml
    ${MINGW_PACKAGE_PREFIX}-python-markupsafe
    ${MINGW_PACKAGE_PREFIX}-python-mistune
    ${MINGW_PACKAGE_PREFIX}-python-packaging
    ${MINGW_PACKAGE_PREFIX}-python-pandocfilters
    ${MINGW_PACKAGE_PREFIX}-python-pygments
    ${MINGW_PACKAGE_PREFIX}-python-tinycss2
    ${MINGW_PACKAGE_PREFIX}-python-traitlets)
makedepends=(
    ${MINGW_PACKAGE_PREFIX}-python-build
    ${MINGW_PACKAGE_PREFIX}-python-installer
    ${MINGW_PACKAGE_PREFIX}-python-hatchling)
source=("https://github.com/jupyter/nbconvert/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('8fdc44fd7d9424db7fdc6e1e834a02f6b8620ffb653767388be2f9eb16f84184')

prepare() {
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  #Todo: Fix a test and possibly nbconvert. The problem is that it attempts
  #to use inkscape but it locates it using the Windows registry and the MINGW
  #version from these doesn't set the registry.
  ${MINGW_PREFIX}/bin/py.test --pyargs nbconvert || true
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 "LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
